Skip to content

Conversation

@long-long-float
Copy link
Contributor

Fix #123068

In the following code, a field value ProcessError::Utf8.0 is used by "{:?}".
However a "never read" warning is shown.

#[derive(Debug)]
enum ProcessError {
    Utf8(i32),
}

fn main() {
    println!("{:?}", ProcessError::Utf8(42));
}
warning: field `0` is never read
 --> test.rs:3:10
  |
3 |     Utf8(i32),
  |     ---- ^^^
  |     |
  |     field in this variant
  |
  = note: `#[warn(dead_code)]` on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
  |
3 |     Utf8(()),
  |          ~~

warning: 1 warning emitted

In this PR, I fixed to mark all enum (for now) fields used by "{:?}".

@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 25, 2024
@asquared31415
Copy link
Contributor

I was under the impression that this was intentional, and that there was meant to be a note along the lines of "Debug is ignored for dead code analysis"

@Noratrieb
Copy link
Member

Yes, if we mark this as used then the lint Iis basically useless.
If you only use a field for its Debug output, apply #[allow(dead_code)] (or in the future, #[expect()]) with a comment about this.

@asquared31415
Copy link
Contributor

There is however a bug here in that there's not a note explaining it

@long-long-float
Copy link
Contributor Author

Oh, I misunderstood. I will make new PR to explain a note about that derived traits by Debug are intentionally ignored.

@Noratrieb
Copy link
Member

cool, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

field "never read" warning for field that is used by derive(Debug)

5 participants